<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>B馆电动车－汽车生活馆</title>
<link  rel="stylesheet" href="{$_C.hy_path}css/car/drawpage.css" />
</head>

<body onload="init()">
	<div class="zonbox">
	    <div class="logo"><img src="{$_C.hy_path}images/car/logo.png" /></div>
	    <div class="yao_bg" id="yao_bg" onclick="ajax_prize()"><img src="{$_C.hy_path}images/car/yao_bg.png" /></div>
	    <div class="yao" id="yao" ><img src="{$_C.hy_path}images/car/yao.png" /></div>
	    <div class="kuan_bg hide" id="kuan_bg">
	    	<img src="{$_C.hy_path}images/car/kuan_bg.png" />
			<div class="gx_bg gift" id="tishi" onclick="jump_card()">
				<p>恭喜您！获得价值<a class="getgift" href="javascript:void(0)">【点击领取】</a></p>
				<p><span class="money" id="money">128元</span><span id="prize_name">驰马牌安全座椅</span></p>
			</div>
	    </div>
	</div>
    <audio loop style="display:none" id="musicBox" src="{$_C.hy_path}images/car/5018.mp3">  
    </audio> 
    <script src="{$_C.hy_path}/js/zepto.min.js"></script>
    
    
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	
<script>
		   
		   
		 
		   
		  wx.config({
		    debug: false, 
		   appId: '{$jsdk.appId}',
				timestamp: {$jsdk.timestamp},
				nonceStr: '{$jsdk.nonceStr}',
				signature: '{$jsdk.signature}',
		    jsApiList: [
		      // 所有要调用的 API 都要加到这个列表中
			  'hideAllNonBaseMenuItem',
	    
		      'addCard',
			 
		     
		    ]
		  });
		
		  
		  wx.ready(function () {
			  wx.hideAllNonBaseMenuItem();
			
		  });
		  
		  
	
		var prize_user_id = "0";
		var is_shake = 0;
		var SHAKE_THRESHOLD = 1000;  
		var last_update = 0;  
		var x = y = z = last_x = last_y = last_z = 0;  
		//音效
		var myaudio = document.getElementById('musicBox');
		
		//跳转领取卡券
		function jump_card()
	    {
	    	window.location.href="index.php?g=mobile&m=car&a=card&id="+prize_user_id;
	    }
	    
		
		//获取是否中奖
	    function ajax_prize()
		  {
			
			  var url = "index.php?g=mobile&m=car&a=ajaxPrize";
				
			  
			  
				$.post(url,"",function(data){
					 
					//alert(data.error);
			         if(data.error==1){
			        	 prize_user_id = data.data.user_id;
			        	 $("#money").html(data.data.money+'元');
			        	 $("#prize_name").html(data.data.prize_name);
			         }else{
			        	 prize_user_id = 0;
			        	 $("#tishi").html('<p>'+data.content+'</p>');
			         }
					 
			           
			           
			           document.getElementById('yao_bg').className='yao_bg move'; 
			            setTimeout(function(){
			            	
			            	
			            	
				            document.getElementById('kuan_bg').className='kuan_bg moveFromBottom'; 
				            document.getElementById('yao').className='yao hide'; 
			            }, 1500);
			            
					 
				},"json");
	  	  
	    	
		  }
	    
	    
		function init() {  
		    
		    if (window.DeviceMotionEvent) {  
		        window.addEventListener('devicemotion', deviceMotionHandler, false);  
		       
		    } else {  
		        alert('not support mobile event');  
		    }  
		}  
		function deviceMotionHandler(eventData) {  
		    var acceleration = eventData.accelerationIncludingGravity;  
		    var curTime = new Date().getTime();  
		    if ((curTime - last_update) > 100) {  
		        var diffTime = curTime - last_update;  
		        last_update = curTime;  
		        x = acceleration.x;  
		        y = acceleration.y;  
		        z = acceleration.z;  
		        var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;  

		        if (speed > SHAKE_THRESHOLD ) { 
		        	
		        	if(is_shake==0)
		        	{
		        		
				        	 ajax_prize();
				        	 is_shake =1;
				        	        
		        	}
		        	
		        	 myaudio.play();
			         setTimeout("myaudio.pause()",1200);   
		            
		        }else {
		            
		             //document.getElementById('yao_bg').className='yao_bg'
		        }
		        last_x = x;  
		        last_y = y;  
		        last_z = z;  
		    }  
		};
	</script>  
</body>
</html>

